﻿#region License
/* Copyright (C) 2009 Tim Coulter
 * 
 * This file is part of ExtremeML.
 * 
 * ExtremeML is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License, as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
*/
#endregion

using DocumentFormat.OpenXml.Spreadsheet;

namespace ExtremeML.Spreadsheet
{
	// This is a partial class that adds custom functionality to its auto-generated partner.
	public sealed partial class SheetWrapperCollection
	{
		#region Custom Properties

//ToDo: This should be implemented as the UniquelyNamedCollectionPattern
		/// <summary>
		/// Gets a <see cref="SheetWrapper"/> by the name of its wrapped <see cref="Sheet"/>.
		/// </summary>
		public SheetWrapper this[string name]
		{
			get { return Items.Find(item => item.Name == name); }
		}

		#endregion
		#region Custom Methods

		/// <summary>
		/// Returns the wrapper for the sheet having the specified id.
		/// </summary>
		/// <param name="id">The id of the target sheet.</param>
		/// <returns>A <see cref="SheetWrapper"/> that matches the specified id. <c>null</c> if no match is found.</returns>
		internal SheetWrapper Find(
			string id)
		{
			return Items.Find(item => item.Id == id);
		}

		/// <summary>
		/// Returns a <see cref="SheetWrapper"/> that wraps a new <see cref="Sheet"/>
		/// with the specified unique name and worksheet relationship id.
		/// </summary>
		/// <param name="name">The unique name of the new worksheet.</param>
		/// <param name="id">The identifier of the sheet part where the definition for this sheet is stored.</param>
		/// <returns>A new instance of <see cref="SheetWrapper"/>.</returns>
		internal SheetWrapper Add(
			string name,
			string id)
		{
			var result = Add();
			result.Name = name;
			result.Id = id;
			result.Activate();
			return result;
		}

		/// <summary>
		/// Deletes the <see cref="SheetWrapper"/> that wraps the sheet having the specified relationship id.
		/// </summary>
		/// <param name="id">The id of the target sheet.</param>
		internal void Delete(
			string id)
		{
			Items.Remove(Items.Find(item => item.Id == id));
		}	

		#endregion
		#region Overrides


		#endregion
		#region Implementation Methods


		#endregion
		#region Static Methods


		#endregion
	}
}
